home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / TwinOpus2 / REXX / DOpus / DeleteFile.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-13  |  4KB  |  146 lines

  1. /*
  2.  *
  3.  * Delete file(s) and dirs with TwinExpres from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  */
  11.  
  12.  
  13. DOpusPort   = 'DOPUS.1'
  14.  
  15. if ~show(l,"rexxsupport.library") then        
  16.     call addlib("rexxsupport.library",0,-30,0)
  17. if showlist('Ports', DOpusPort) = 0 then do
  18.    say 'Directory Opus Arexx port not found. Aborting.'
  19.    call CleanUp
  20. end
  21.  
  22. address 'DOPUS.1'
  23. options results
  24.  
  25. /* setup DOpus window and tell user what's happening */
  26. Busy on
  27. request "Are you sure you want to all selected entries?"
  28. if result = 0 then exit
  29. TopText "Deleting selected files..."
  30.  
  31.  
  32. /* Get the current path and do file-deletion, depending on the  */
  33. /* type of path (Twin-path or normal path)                  */
  34. 'Status 6 -1'
  35. GetEntry Result
  36. FilePath = Result
  37.  
  38. /* Twin-way */
  39. if left(FilePath,1) = '*' then do
  40.    FilePath = SubStr(FilePath,2)
  41.    GetSelectedAll
  42.    SelectedEntries = result
  43.    if SelectedEntries = 'RESULT' then do
  44.       TopText "No files selected."
  45.       call CleanUp
  46.    end
  47.    NumberOfEntries = words(SelectedEntries)
  48.    do EntryNumber = 1 to NumberOfEntries
  49.       Index = word(SelectedEntries, EntryNumber)
  50.       GetEntry Index+1
  51.       Entry = result
  52.       File = strip(left(Entry,25))
  53.       if right(FilePath,1) = ':' then
  54.          File = Quote(FilePath || File)
  55.       else
  56.          File = Quote(FilePath || '/' || File)
  57.       if SubStr(Entry,26,9) = "Directory" then
  58.          address command 'echo >PPipe: RMDir' File
  59.       else
  60.          address command 'echo >PPipe: delete' File 'ALL'
  61.       selection = Index||' 0 0'
  62.       SelectEntry selection
  63.    end
  64. end
  65.  
  66. /* Normal way */
  67. else do
  68.    'Status 13 -1'
  69.    FilePath = result
  70.    if FilePath = '' then do
  71.       TopText "No source directory selected."
  72.       call CleanUp
  73.    end
  74.    'GetSelectedAll "|" -1'
  75.    SelectedEntries = result
  76.    if SelectedEntries = 'RESULT' then do
  77.       TopText "No files selected."
  78.       call CleanUp
  79.    end
  80.    NumberOfEntries = CountWords(SelectedEntries)
  81.    do EntryNumber = 1 to NumberOfEntries
  82.       File = GetWord(EntryNumber, SelectedEntries)
  83.       SelectFile File
  84.       if right(FilePath,1) = ':' then
  85.          File = Quote(FilePath || File)
  86.       else
  87.          File = Quote(FilePath || '/' || File)
  88.       address command 'echo >PPipe: delete' File 'ALL'
  89.    end
  90. end
  91.  
  92.  
  93. TopText "Ready"
  94. 'DisplayDir -1'
  95. address AREXX "Rexx:DOpus/Reread.rexx"
  96. call CleanUp
  97.  
  98. exit
  99.  
  100. /*---------------------------------------------------------------------------*/
  101.  
  102. CleanUp: /* Remove any files and exit */
  103.    Busy off
  104.    exit
  105. return
  106.  
  107. /*--------------------------------------------------------------------------*/
  108.  
  109. Quote: procedure /* add quotes to string */
  110.    parse arg string
  111. return '"'||string||'"'
  112.  
  113. /*--------------------------------------------------------------------------*/
  114.  
  115. GetWord: procedure /* get word from '|' separated string */
  116.  
  117.   parse arg number,words
  118.  
  119.   if(left(words,1) ~= '|') then
  120.      words = '|'||words
  121.   do i=1 to number
  122.      idx = index(words, '|');
  123.      words = substr(words, idx+1)
  124.   end
  125.   end = index(words, '|') - 1
  126.   if words = "" then
  127.      return ""
  128.   ret_str = substr(words, 1, end)
  129. return ret_str
  130.  
  131. /*--------------------------------------------------------------------------*/
  132.  
  133. CountWords: procedure /* count words from '|' separated string */
  134.  
  135.    parse arg words
  136.  
  137.    count = 0
  138.    idx = index(words, '|')
  139.    do while idx ~= 0
  140.      count = count + 1
  141.      words = substr(words, idx+1)
  142.      idx = index(words, '|')
  143.    end
  144. return count
  145.  
  146.